package com.briup.srms.sms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.srms.sms.bean.Dormitory;
import com.briup.srms.sms.bean.extend.DormitoryExtend;
import com.briup.srms.sms.dao.DormitoryMapper;
import com.briup.srms.sms.dao.extend.DormitoryExtendMapper;
import com.briup.srms.sms.service.IDormitoryService;
import com.jacky.base.utils.CustomerException;
import com.jacky.base.utils.PageVM;

@Service
public class DormitoryServiceImpl implements IDormitoryService {

	@Autowired
	private DormitoryMapper dormitoryMapper;
	@Autowired
	private DormitoryExtendMapper dormitoryExtendMapper;
	
	@Override
	public PageVM<DormitoryExtend> pageQuery(int page, int pageSize,Long dormitoryTypeId) {
		List<DormitoryExtend> list = dormitoryExtendMapper.query(page, pageSize,dormitoryTypeId);
		long total = dormitoryExtendMapper.count(dormitoryTypeId);
		return new PageVM<>(page, pageSize, total, list);
	}
	@Override
	public void saveOrUpdate(Dormitory dormitory) {
		if(dormitory.getId() == null) {
			dormitoryMapper.insert(dormitory);
		} else {
			dormitoryMapper.updateByPrimaryKey(dormitory);
		}
		
	}
	@Override
	public void deleteById(long id) {
		// TODO Auto-generated method stub
		Dormitory dict = dormitoryMapper.selectByPrimaryKey(id);
		if(dict == null) {
			throw new CustomerException("要删除的数据不存在");
		}
		dormitoryMapper.deleteByPrimaryKey(id);
		
	}
}
